/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[InnerClass2.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package objectOriented;

/**
 * 静态内部类
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class InnerClass2 {

	private static int i = 10;

	@SuppressWarnings("unused")
	private int d = 20;

	/**
	 * 
	 * @author 不落的太阳(Sean Yang aka ShortPeace)
	 * @version 1.0
	 * @since jdk 1.8
	 *
	 */
	private static class StaticInnerClass {

		static {
			System.out.println("static_class static block");
		}

		{
			System.out.println("static_class initial block");
		}

		public StaticInnerClass() {
			System.out.println("static_class constructor");
		}

		public void method() {
			InnerClass2.i = 40;
			System.out.println(InnerClass2.i);
			// System.out.println(d); 静态内部类不能访问外部类的非静态变量
		}
	}

	/**
	 * 
	 * @author 不落的太阳(Sean Yang aka ShortPeace)
	 * @version 1.0
	 * @since jdk 1.8
	 *
	 */
	public static class Pair {

		private double first;
		private double second;

		public Pair(double first, double second) {
			this.first = first;
			this.second = second;
		}

		public double getFirst() {
			return first;
		}

		public double getSecond() {
			return second;
		}

		@Override
		public String toString() {
			return "Pair [first=" + first + ", second=" + second + "]";
		}
	}

	/**
	 * 查找一个double数组中的最大值和最小值
	 * 
	 * 当一个方法返回值有多个的时候, 可以考虑使用内部类来解决问题
	 * 
	 * @param values
	 * @return Pair对象
	 */
	public static Pair minmax(double[] values) {
		double min = Double.MAX_VALUE;
		double max = Double.MIN_VALUE;

		for (double d : values) {
			if (min > d) {
				min = d;
			}
			if (max < d) {
				max = d;
			}
		}
		return new Pair(min, max);
	}

	public static void main(String[] args) {
		InnerClass2.StaticInnerClass staticInnerClass = new InnerClass2.StaticInnerClass();
		staticInnerClass.method();

		System.out.println();

		double[] values = { 10.0, 12.0, 11.0, 13.0, 15.0, 14.0 };
		InnerClass2.Pair pair = InnerClass2.minmax(values);
		System.out.println(pair);
	}
}
